package com.shilei.obsever.v1;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:  观察者   观察小孩哭  做出相应处理
 * @author: 81271
 * @date: 2020-04-17 20:32
 */
public class Main1 {

    public static void main(String[] args) {
        Children children = new Children();

        children.wakeUp();
    }


}



class Children {
    private boolean cry = false;

    List<Observer> observerList = new ArrayList<>();

    {
        observerList.add(new Dad());
        observerList.add(new Mom());
    }

    boolean isCry() {
        return cry;
    }

    void wakeUp () {
        cry = true;
        System.out.println("crying   wuwawuwawuwa!!!!");

        for (Observer observer: observerList) {
            observer.observerWakeUp();
        }
    }
}

interface Observer {
    void observerWakeUp();
}

class Dad implements Observer {
    public void feed() {
        System.out.println("dad  feeding.....");
    }

    @Override
    public void observerWakeUp() {
        feed();
    }
}

class Mom implements Observer {
    public void tellStory() {
        System.out.println("mom  telling story.....");
    }

    @Override
    public void observerWakeUp() {
        tellStory();
    }
}
